package pers.vic.test.some.pandc;

import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 生产者
 * @author VIC
 *
 */
public class Producer implements Runnable{

	private BlockingQueue<Integer> queue;
	
	
	
	public Producer(BlockingQueue<Integer> queue) {
		super();
		this.queue = queue;
	}



	@Override
	public void run() {
		try {
			while(true) {
				TimeUnit.SECONDS.sleep(2);
				queue.put(produce());
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
	}



	private Integer produce() {
		int n = new Random().nextInt(10000);
		String s = Thread.currentThread().getName()  + "--> 生产:" + n;
		System.out.println(s);
		return n;
	}

}
